package com.cat.bitOperation;

import java.util.HashMap;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/count-triplets-that-can-form-two-arrays-of-equal-xor/description/
 * @create 2025/8/20 10:21
 * @since JDK17
 */

public class Solution06 {
    public int countTriplets(int[] arr) {
        int ans = 0, n = arr.length, xor = 0;
        int[] prefix = new int[n + 1];
        for (int i = 0; i < n; i++) {
            prefix[i + 1] = prefix[i] ^ arr[i];
        }

        for (int j = 1; j < n; j++) {   // 中间位置
            xor ^= arr[j - 1];  //
            for (int i = 0, pre; i < j; i++) {
                pre = xor ^ prefix[i];
                for (int k = j; k < n; k++) {
                    ans += (prefix[k + 1] ^ xor) == pre ? 1 : 0;
                }
            }
        }
        return ans;
    }
}

